package com.csdj.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Author : 今晚几点睡_Ada
 * Date: 2022/8/5
 * Time: 10:26
 * 注: 登录拦截
 */

public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //登录成功之后，应该有用户的session
        Object user = request.getSession().getAttribute("LoginUser");
        if (user==null){
           // request.getRequestDispatcher("login.html").forward(request,response);
            response.sendRedirect("login.html");
            return false;
        }else {
            return true;
        }
    }
}
